package com.icity.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.icity.entity.Echartpie;
import com.icity.entity.content.Catalog;
import com.icity.entity.screen.ScreenNum;
import com.icity.mapper.AdMapper;
import com.icity.mapper.ScreenMapper;
import com.icity.service.ScreenService;

@Service
public class ScreenServiceImpl implements ScreenService{

	@Autowired
	private ScreenMapper screenMapper;

	@Override
	public Echartpie getCatalogpie(Map<Object, Object> map) {
		Echartpie echartpie = new Echartpie();
		Map<Object, String> tooltip = new HashMap<Object, String>();
		tooltip.put("trigger", "item");
		tooltip.put("formatter", "{a} <br/>{b}: {c} ({d}%)");
		List<Map<Object, Object>> series = new ArrayList<Map<Object, Object>>();
		Map<Object, Object> seriesMap = new HashMap<Object, Object>();
		seriesMap.put("name", "访问来源");
		seriesMap.put("type", "pie");
		//String radius[] = { "50%", "70%" };
		seriesMap.put("radius", "65%");
		seriesMap.put("avoidLabelOverlap", false);
		List<Map<Object, Object>> listData = new ArrayList<Map<Object, Object>>();
		List<ScreenNum> list = screenMapper.getCatalogByDate(map);
		int videoCount = 0;
		int musicCount = 0;
		int bookCount = 0;
		int magazineCount = 0;
		int paperCount = 0;
		int articleCount = 0;
		int afficheCount = 0;
		int screenCount = 0;
		for (ScreenNum screen : list) {
			videoCount += screen.getVideo();
			musicCount += screen.getMusic();
			bookCount += screen.getBook();
			magazineCount += screen.getMagezine();
			paperCount += screen.getPaper();
			articleCount += screen.getArticle();
			afficheCount += screen.getAffiche();
			screenCount += screen.getScreen();
		}
		Map<Object, Object> mapVideo = new HashMap<Object, Object>();
		mapVideo.put("name", "视频");
		mapVideo.put("value", videoCount);
		Map<Object, Object> mapMusic = new HashMap<Object, Object>();
		mapMusic.put("name", "音频");
		mapMusic.put("value", musicCount);
		Map<Object, Object> mapBook = new HashMap<Object, Object>();
		mapBook.put("name", "图书");
		mapBook.put("value", bookCount);
		Map<Object, Object> mapMagazine = new HashMap<Object, Object>();
		mapMagazine.put("name", "期刊");
		mapMagazine.put("value", magazineCount);
		Map<Object, Object> mapPaper = new HashMap<Object, Object>();
		mapPaper.put("name", "报纸");
		mapPaper.put("value", paperCount);
		Map<Object, Object> mapArticle = new HashMap<Object, Object>();
		mapArticle.put("name", "文章");
		mapArticle.put("value", articleCount);
		Map<Object, Object> mapAffiche = new HashMap<Object, Object>();
		mapAffiche.put("name", "公告");
		mapAffiche.put("value", afficheCount);
		Map<Object, Object> mapScreen = new HashMap<Object, Object>();
		mapScreen.put("name", "开屏");
		mapScreen.put("value", screenCount);
		listData.add(mapVideo);
		listData.add(mapMusic);
		listData.add(mapBook);
		listData.add(mapMagazine);
		listData.add(mapPaper);
		listData.add(mapArticle);
		listData.add(mapAffiche);
		listData.add(mapScreen);
		seriesMap.put("data", listData);
		series.add(seriesMap);
		echartpie.setTooltip(tooltip);
		echartpie.setSeries(series);
		return echartpie;
	}

}
